import axios from 'axios'

// axios.defaults.baseURL = '//47.98.61.156'
axios.defaults.baseURL = '/'
axios.defaults.withCredentials = true

axios.interceptors.request.use(config => {
  config.headers = Object.assign(config.headers, {
    'X-Requested-With': 'XMLHttpRequest'
  })
  return config
})

axios.interceptors.response.use(response => {
  return response.data
}, () => {
  return { code: 1001, message: '系统错误, 请稍后再试' }
})

export const get = (url, params, options) => {
  return axios.get(url, { params, ...options })
}

export const post = (url, data, options) => {
  return axios.post(url, data, options)
}
